package backend.Instruction;

import backend.Register.RISCVoperand;

import java.util.List;

public class RISCVla extends RISCVinst {
    private List<RISCVoperand> operands;

    public RISCVla(List<RISCVoperand> operands) {
        this.operands = operands;
        setDst(operands.get(0));
        setAddress(operands.get(1));
    }
    public void setDst(RISCVoperand dst) {
        setDefReg(operands.get(0), dst);
        operands.set(0, dst);
    }

    public void setAddress(RISCVoperand address) {
        addUseReg(operands.get(1), address);
        operands.set(1, address);
    }

    public void replaceReg(RISCVoperand oldReg, RISCVoperand newReg) {
        if (operands.get(0).equals(oldReg)) {
            setDst(newReg);
        }
        if (operands.get(1).equals(oldReg)) {
            setAddress(newReg);
        }
    }

    public RISCVoperand getDst() {
        return operands.get(0);
    }

    public RISCVoperand getAddress() {
        return operands.get(1);
    }

    @Override
    public String toString() {
        return "la" + " " + operands.get(0) + ", "  + operands.get(1) + "\n";
    }
}
